<template>
  <ex-dialog v-model="visible" draggable :title="selectorName" width="1200" footershow="none">
    <template #default>
        <el-container>
          <el-aside class="nopadding dialogsearch" style="width: 300px;padding-top: 10px;">
          <search-form :searches="searches" :search-form="searchForm"></search-form>
            <div style="flex: auto;text-align: center;padding-left: 40px;">
              <el-button plain type="primary" icon="el-icon-search" @click="searchHandler" :loading="loading">
                {{ $t('button.search_ok') }}
              </el-button>
              <el-button plain type="warning" icon="el-icon-brush" @click="resetHandler">{{ $t('button.search_clear') }}
              </el-button>
            </div>
          </el-aside>
          <el-main class="nopadding">
            <ex-table id="assetTable" ref="assetSelecterTable" :columns="columns" :height="380" size="small" :url="this.$API.asset.syncBatchDetail.pageData.url" :params="form" :refs="this.$refs" :checkbox-init="checkboxInit" @columnClick="columnClickHandler"></ex-table>
            <div style="flex: auto;text-align: center;margin-top: 5px;margin-bottom: 10px;">
              <el-button plain type="primary" @click="save" :loading="loading">确 定</el-button>
              <el-button plain type="info" @click="this.visible = false" :loading="loading">取 消</el-button>
            </div>
          </el-main>
        </el-container>
    </template>
    </ex-dialog>
  <data-card ref="dataCard"></data-card>
</template>

<script>
import scIconSelect from '@/components/scIconSelect/index.vue'
import exDialog from '@/components/exDialog';
import ExRelTable from "@/components/exRelTable/index.vue";
import ExLabel from "@/components/exLabel/index.vue";
import ExFormItem from "@/components/exFormItem/index.vue";
import ExTable from "@/components/exTable/index.vue";
import ExSearch from "@/components/exSearch/index.vue";
import DataCard from "@/views/asset/card/card.vue";
import SearchForm from "@/components/exSearch/search_form.vue";
import {h} from "vue";
import globalparam from "@/constant/model/globalparam";

export default {
  name:"oarkSelecter",
  computed: {},
  emits: ['success'],
  components: {
    SearchForm,
    DataCard,
    ExSearch, ExTable,
    ExFormItem,
    ExLabel,
    ExRelTable,
    scIconSelect,
    exDialog
  },
  props: {
    details:{type:Array,default:[]}
  },
  data() {
    return {
      activeName: 'base',
      visible: false,
      form: {
      },
      model:{},
      loading: false,
      oldForm: null,
      searchForm:{},
      searches: [
        {type: "input", name: "申购单号", code: "batchName"},
      ],
      columns: [
        {code: "batchName", name: "申购单号",width: "200",align:"center"},
        {code: "other.assetInfo.name", name: "资产名称", width:"150",align:"center"},
        {code: "other.assetInfo.originalValue", name: "单价", width:"100",align:"right"},
        {code: "other.assetInfo.assetCategoryId", name: "资产分类",width:"150", formatter:"DICT",key: "FamsAssetCategory",align:"center"},
        {code: "other.assetInfo.usingMenId", name: "使用人", width:"100",formatter:"DICT",key: "SysUser",align:"center"},
        {code: "other.assetInfo.usingDepartmentId", name: "使用部门", width:"200",formatter:"DICT",key: "SysOrganization",align:"center"},
        {code: "other.assetInfo.assetCount", name: "资产数量", width:"100",align: "right"},
        {code: "other.assetInfo.brand", name: "品牌", width:"150",align:"center"},
        {code: "other.assetInfo.model", name: "规格型号", width:"150",align:"center"},
      ],
    }
  },
  watch: {},
  mounted() {

  },
  onLoad() {
  },
  methods: {
	  checkboxInit(row,index){
		 return 1;
	  },
    async initData() {
    },
    //显示
    async open(entity) {
      this.form = Object.assign({}, entity);
      this.oldForm = this.$TOOL.objCopy(this.oldForm);
      this.visible = true;
      this.resetHandler();
      this.initData();
    },
    async close(){
      //this.$refs.assetselecter.onClose();
      this.visible = false;
    },
    async searchHandler() {
      await this.$refs.assetSelecterTable.refresh(this.searchForm);
    },
    resetHandler() {
      this.searchForm = {};
    },
    columnClickHandler(name,data){
      this.$options.methods[name](this, data);
    },
    //保存
    async save() {
      let selections = this.$refs.assetSelecterTable.selections();
      if (selections.length === 0) {
        this.$message.warning(this.$t("common.please_select_data"));
        return;
      }

      let confirm = await this.$confirm('请确认是否提交选择的资产', '警告', {type: 'warning'}).then(() => {return true;}).catch(() => {return false;});
      if (!confirm) return;
	  //清空集合的所有数量，重新设值
	  this.details.splice(0,this.details.length);
	  selections.forEach(row=>{
		  this.details.push(row.other);
	  })

      this.$emit('success');
      this.visible = false;
    },
  }
}
</script>

<style scoped>
h2 {
  font-size: 17px;
  color: #3c4a54;
  padding: 0 0 30px 0;
}

[data-theme="dark"] h2 {
  color: #fff;
}


::v-deep(.dialogselect .el-dialog__header){
  padding: 0px !important;
  margin-right: 0px;
}
::v-deep(.dialogsearch){
 padding-top: 10px;
}

::v-deep(.dialogsearch .el-form-item--default .el-form-item__label){
  font-size: 13px !important;
  color: rgb(101, 101, 101) !important;
}

::v-deep(.dialogsearch .el-form-item--default .el-input__inner,.dialogsearch .el-form-item--default .el-date-editor){
  font-size: 13px !important;

}


</style>
